Vue.component('Add', {
	template: `
		<el-dialog title="添加" width="600px" class="icon-dialog" :visible.sync="show" @open="open" :before-close="closeForm" append-to-body>
			<el-form :size="size" ref="form" :model="form" :rules="rules" :label-width=" ismobile()?'90px':'16%'">
				<el-row >
					<el-col :span="24">
						<el-form-item label="标题" prop="title">
							<el-input  v-model="form.title" autoComplete="off" clearable  placeholder="请输入标题"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="wangeditor编辑器" prop="wangeditor">
							<wang-editor v-if="show"  :is_clear="is_clear" :wangcontent.sync="form.wangeditor"></wang-editor>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="tinymce编辑器" prop="ueditor">
							<tinymce v-if="show"  :content.sync="form.ueditor"></tinymce>
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button :size="size" :loading="loading" type="primary" @click="submit" >
					<span v-if="!loading">确 定</span>
					<span v-else>提 交 中...</span>
				</el-button>
				<el-button :size="size" @click="closeForm">取 消</el-button>
			</div>
		</el-dialog>
	`
	,
	components: {
	},
	props: {
		show: {
			type: Boolean,
			default: false
		},
		size: {
			type: String,
			default: 'small'
		},
	},
	data() {
		return {
			form: {
				title: '',
				wangeditor: '',
				ueditor: '',
			},
			is_clear: false,
			loading: false,
			rules: {
			}
		}
	},
	methods: {
		open() {
		},
		submit() {
			this.$refs['form'].validate(valid => {
				if (valid) {
					this.loading = true
					axios.post('/admin/Editor/add', this.form).then(res => {
						if (res.data.status == 200) {
							this.$message({ message: res.data.msg, type: 'success' })
							this.$emit('refesh_list')
							this.closeForm()
						} else {
							this.loading = false
							this.$message.error(res.data.msg)
						}
					}).catch(() => {
						this.loading = false
					})
				}
			})
		},
		closeForm() {
			this.$emit('update:show', false)
			this.loading = false
			if (this.$refs['form'] !== undefined) {
				this.$refs['form'].resetFields()
			}
			this.is_clear = true
		},
	}
})
